//
//  MBProgressHUD+WZ.m
//  ETong
//
//  Created by wanzhao on 15/11/5.
//  Copyright (c) 2015年 wanzhao. All rights reserved.
//

#import "MBProgressHUD+WZ.h"
#import "UIImageView+PlayGIF.h"

@implementation MBProgressHUD (WZ)

#pragma mark 显示信息
+ (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view
{
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];

    hud.labelText = text;
    // 设置图片
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    
    hud.opacity = 0.8f;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    
    // 1秒之后再消失
    [hud hide:YES afterDelay:1.0f];
}


+(void)showSignSuccessToview:(UIView *)view
{
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    // 设置图片
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bigYinzhang"]];
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    
    hud.opacity = 0.0f;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    
    // 1秒之后再消失
    [hud hide:YES afterDelay:1.0f];

}

+(void)showSignOutSuccessToview:(UIView *)view
{
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    // 设置图片
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bigSignOutYinzhang"]];
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    
    hud.opacity = 0.0f;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    
    // 1秒之后再消失
    [hud hide:YES afterDelay:1.0f];
    
}

#pragma mark 显示错误信息
+ (void)showError:(NSString *)error toView:(UIView *)view{
    [self show:error icon:@"error.png" view:view];
}

+ (void)showSuccess:(NSString *)success toView:(UIView *)view
{
    [self show:success icon:@"success.png" view:view];
}

#pragma mark 显示一些信息
+ (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.labelText = message;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // YES代表需要蒙版效果
    hud.dimBackground = NO;

//    // 快速显示一个提示信息
//     MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
//    if (message != nil && message.length > 0) {
//        hud.labelText = message;
//    }
//    
//    UIImageView *gif = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, OppositeWidthRate(24), OppositeWidthRate(24))];
//    gif.image = [UIImage imageNamed:@"load_flash_image"];
//    gif.gifData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"load_gif_image.gif" ofType:nil]];
//    [gif startGIF];
//    hud.customView = gif;
//    hud.mode = MBProgressHUDModeCustomView;
//    // 隐藏时候从父控件中移除
//    hud.removeFromSuperViewOnHide = YES;
//    // YES代表需要蒙版效果
//    hud.dimBackground = NO;
    return hud;
}

+ (void)showSuccess:(NSString *)success
{
    [self showSuccess:success toView:nil];
}

+ (void)showError:(NSString *)error
{
    [self showError:error toView:nil];
}

+ (MBProgressHUD *)showMessage:(NSString *)message
{
    return [self showMessage:message toView:nil];
}

+ (void)hideHUDForView:(UIView *)view
{
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    [self hideHUDForView:view animated:YES];
}

+ (void)hideHUD
{
    [self hideHUDForView:nil];
}


@end
